package com.iakuil.mvp.mp.common;

import com.iakuil.mvp.mp.common.domain.BaseEntity;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * IBaseService
 *
 * @author Kai
 * @date 2021/12/17 17:03
 **/
public interface IBaseService<T extends BaseEntity> {
    @Transactional(readOnly = true)
    List<T> listAll();

    @Transactional(readOnly = true)
    List<T> list(T entity);

    @Transactional(readOnly = true)
    T getById(Serializable id);

    @Transactional(readOnly = true)
    List<T> getByIds(Serializable... ids);

    @Transactional(readOnly = true)
    T getOne(T entity);

    @Transactional(readOnly = true)
    long count(T entity);

    @Transactional(readOnly = true)
    boolean exists(T entity);

    @Transactional(readOnly = true)
    boolean exists(Serializable id);

    @Transactional(rollbackFor = Exception.class)
    boolean save(T entity);

    @Transactional(rollbackFor = Exception.class)
    boolean saveBatch(List<T> entities, int chunkSize);

    @Transactional(rollbackFor = Exception.class)
    boolean saveBatch(List<T> entities);

    @Transactional(rollbackFor = Exception.class)
    boolean modify(T entity);

    @Transactional(rollbackFor = Exception.class)
    boolean saveOrModify(T entity);

    @Transactional(rollbackFor = Exception.class)
    boolean remove(Serializable id);

    @Transactional(rollbackFor = Exception.class)
    boolean removeByIds(Serializable... ids);
}
